package com.taldh.algorithm.动态规划;

import org.junit.Assert;
import org.junit.Test;

public class Fib {

    public int fib(int n) {
        if (n < 1) {
            return 0;
        }
        if (n < 3) {
            return 1;
        }
        int i = 1;
        int j = 1;
        int fn = 0;
        for (int k = 3; k < n + 1; k++) {
            fn = i + j;
            if (k % 2 == 1) {
                i = fn;
            } else {
                j = fn;
            }
        }
        return fn;
    }

    @Test
    public void test() {
        Assert.assertEquals(3, fib(4));
    }
}